//
//  YXLoginView.m
//  CreditCard
//
//  Created by 杨旭 on 2017/12/26.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "YXLoginView.h"

@interface YXLoginView ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIView *backView;

@end

@implementation YXLoginView
-(instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        NSArray *viewArray = [[NSBundle mainBundle]loadNibNamed:@"YXLoginView" owner:self options:nil];
        self = viewArray[0];
        self.frame = frame;
        // 添加背景渐变色
        CAGradientLayer *gradient = [CAGradientLayer layer];
        gradient.frame = self.backView.bounds;
        gradient.colors = [NSArray arrayWithObjects:
                           (id)[UIColor colorWithRed:0 green:143/255.0 blue:234/255.0 alpha:1.0].CGColor,
                           (id)[UIColor colorWithRed:0 green:193/255.0 blue:234/255.0 alpha:1.0].CGColor,
                           (id)[UIColor cyanColor].CGColor, nil];
        [self.backView.layer addSublayer:gradient];
        
        [self setup];
    }
    return self;
    
}

- (void)setup {
    
    
    if ([[NSUserDefaults standardUserDefaults] objectForKey:kPHONE]) {
        _accountTF.text = [[NSUserDefaults standardUserDefaults] objectForKey:kPHONE];
    } else {
        _accountTF.text = @"";
    }
    self.accountTF.delegate = self;
    self.passwordTF.delegate = self;
    self.forgetBtn.tag = 800;
    self.registBtn.tag = 801;
    self.loginBtn.tag = 802;
    self.loginBtn.layer.masksToBounds = YES;
    self.loginBtn.layer.cornerRadius = 20.0f;
}

- (IBAction)selctBtnAction:(UIButton *)sender {
    
    if (self.selectBtnClickBlock) {
        self.selectBtnClickBlock(sender.tag - 800);
    }
    
}

- (IBAction)secureBtnAction:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (sender.selected == YES) {
        self.passwordTF.secureTextEntry = NO;
    }else if(sender.selected == NO){
        self.passwordTF.secureTextEntry = YES;
    }
}
#pragma mark -TextField代理方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    return [textField resignFirstResponder];
}

@end
